#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/12/27 11:50
# @Author: hekang
# @Email: 591785757@qq.com
# @File：recipes_page.py
from appium.webdriver.common.mobileby import MobileBy as By
from pages.base_page import BasePage



class RecipesPage(BasePage):
    '''定位器'''
    recommend_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_how_recommend\"]")
    text_recommend_locator = (
        By.XPATH, "//android.webkit.WebView[@resource-id=\"com.gfeng.daydaycook:id/webView\"]")
    recipes_cover_locator = (
        By.XPATH, "//android.widget.LinearLayout[@resource-id=\"com.gfeng.daydaycook:id/ll_cover_text\"]")
    recipes_title_locator = (
        By.XPATH, "//android.widget.EditText[@resource-id=\"com.gfeng.daydaycook:id/et_recipe_name\"]")
    recipes_content_locator = (
        By.XPATH, "//android.widget.EditText[@resource-id=\"com.gfeng.daydaycook:id/et_recipe_description\"]")
    recipes_next_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_next\"]")
    recipes_send_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_publish\"]")
    recipes_food_locator = (
        By.XPATH, "//android.widget.EditText[@resource-id=\"com.gfeng.daydaycook:id/et_food_name\"]")
    recipes_consumption_locator = (
        By.XPATH, "//android.widget.EditText[@resource-id=\"com.gfeng.daydaycook:id/et_num_unit\"]")
    recipes_step_picture_locator = (
        By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]"
                  "/android.widget.RelativeLayout[2]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]"
                  "/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]")
    recipes_step_content_locator = (
        By.XPATH, "//android.widget.EditText[@resource-id=\"com.gfeng.daydaycook:id/et_step_description\"]")
    recipes_type_add_locator = (
        By.XPATH, "//android.view.ViewGroup[@resource-id=\"com.gfeng.daydaycook:id/tfl_recipe_category\"]"
                  "/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]")
    recipes_join_locator = (
        By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/tv_recipe_tag\"]")
    recipes_join_select_locator = (
        By.XPATH,
        "//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/recommend_recyclerview\"]"
        "/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]"
        "/android.widget.LinearLayout[1]")
    recipes_main_food_locator = (
        By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]"
                  "/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]"
                  "/android.widget.RelativeLayout[2]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]"
                  "/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]"
                  "/android.widget.EditText[1]")
    assert_send_locator = (
        By.XPATH, "//android.widget.TextView[@text=\"分享到\"]")

    # 点击如何成为被推荐食谱
    def recommend(self):
        self.find_element(self.recommend_locator).click()

    # 菜谱封面
    def recipes_cover(self):
        self.find_element(self.recipes_cover_locator).click()

    # 食谱菜名
    def recipes_title(self, title):
        self.find_element(self.recipes_title_locator).send_keys(title)

    # 菜名详述
    def recipes_content(self, content):
        self.find_element(self.recipes_content_locator).send_keys(content)

    # 食谱下一步
    def recipes_next(self):
        self.find_element(self.recipes_next_locator).click()

    # 写入食材
    def recipes_food(self, food):
        self.find_element(self.recipes_food_locator).send_keys(food)

    # 食材用量
    def recipes_consumption(self, consumption):
        self.find_element(self.recipes_consumption_locator).send_keys(consumption)

    # 添加步骤图
    def recipes_step_picture(self):
        self.find_element(self.recipes_step_picture_locator).click()

    # 输入步骤内容
    def recipes_step_content(self, step_content):
        self.find_element(self.recipes_step_content_locator).send_keys(step_content)

    # 增加食谱分类
    def recipes_type_add(self):
        self.find_element(self.recipes_type_add_locator).click()

    # 点击参加话题
    def recipes_join(self):
        self.find_element(self.recipes_join_locator).click()

    # 选择话题
    def recipes_join_select(self):
        self.find_element(self.recipes_join_select_locator).click()

    # 提取主要食材文本
    def recipes_main_food(self):
        return self.find_element(self.recipes_main_food_locator).text

    # 发布食谱
    def recipes_send(self):
        self.find_element(self.recipes_send_locator).click()

    # 断言"分享到"
    def assert_send(self):
        return self.find_element(self.assert_send_locator).text


